home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bench / sun4.md / RCS / printStats.c,v < prev   
Text File  |  1991-10-09  |  27KB  |  816 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     90.09.24.14.37.16;  author douglis;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.08.28.22.51.29;  author douglis;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @routines to print statistics.
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @print stats for values at regular intervals
  28. @
  29. text
  30. @/*
  31.  * printStats.c --
  32.  *    Routines to print out program execution times, and filesystem stats.
  33.  */
  34.  
  35. #include "sprite.h"
  36. #include "status.h"
  37. #include "sys/ioctl.h"
  38. #include "sys/file.h"
  39. #include "stdio.h"
  40. #include "proc.h"
  41. #include "vm.h"
  42. #include "sysStats.h"
  43. #include "kernel/fs.h"
  44. #include "kernel/fsStat.h"
  45. #include "kernel/sched.h"
  46. #include "kernel/vm.h"
  47. #include "kernel/net.h"
  48.  
  49.  
  50.  
  51. /*
  52.  *----------------------------------------------------------------------
  53.  *
  54.  * PrintTimes --
  55.  *
  56.  *    Print the resource usage (user and kernel CPU time) and elapsed time.
  57.  *
  58.  * Results:
  59.  *    None.
  60.  *
  61.  * Side effects:
  62.  *    Prints to the specified stream
  63.  *
  64.  *----------------------------------------------------------------------
  65.  */
  66. void
  67. PrintTimes(stream, usagePtr, timePtr)
  68.     FILE *stream;
  69.     Proc_ResUsage *usagePtr;
  70.     Time *timePtr;
  71. {
  72.     Time delta;
  73.     if (usagePtr != NULL) {
  74.     Time_Add(usagePtr->userCpuUsage, usagePtr->childUserCpuUsage,
  75.                      &delta);
  76.     fprintf(stream, "%d.%03du ", delta.seconds,
  77.                    delta.microseconds / 1000);
  78.     Time_Add(usagePtr->kernelCpuUsage, usagePtr->childKernelCpuUsage,
  79.                      &delta);
  80.     fprintf(stream, "%d.%03ds ", delta.seconds,
  81.                    delta.microseconds / 1000);
  82.     }
  83.     if (timePtr != NULL) {
  84.     int seconds = timePtr->seconds;
  85.     if (seconds >= 3600) {
  86.         fprintf(stream, "%d:", seconds / 3600);
  87.         seconds = seconds % 3600;
  88.     }
  89.     if (seconds >= 60) {
  90.         fprintf(stream, "%d:", seconds / 60);
  91.         seconds = seconds % 60;
  92.     }
  93.     fprintf(stream, "%d.%03d", seconds,
  94.                    timePtr->microseconds / 1000);
  95.     }
  96.     fprintf(stream, "\n");
  97. }
  98.  
  99.  
  100. /*
  101.  *----------------------------------------------------------------------
  102.  *
  103.  * PrintIdleTime --
  104.  *
  105.  *    Given two samples sched module statistics, this computes
  106.  *    the differenc in idle ticks and, using the time, computes
  107.  *    a utilization.
  108.  *
  109.  * Results:
  110.  *    None.
  111.  *
  112.  * Side effects:
  113.  *    Prints to the specified stream
  114.  *
  115.  *----------------------------------------------------------------------
  116.  */
  117. void
  118. PrintIdleTime(stream, startSchedPtr, endSchedPtr, timePtr)
  119.     FILE *stream;
  120.     Sched_Instrument *startSchedPtr, *endSchedPtr;
  121.     Time *timePtr;
  122. {
  123.     register     highTicks;
  124.     double     lowTicks;
  125.     int        cpu;
  126.  
  127.     Sched_Instrument zeroStats;
  128.     if (startSchedPtr == NULL) {
  129.     bzero(&zeroStats, sizeof(Sched_Instrument));
  130.     startSchedPtr = &zeroStats;
  131.     }
  132.  
  133.     for (cpu=0; cpu<MACH_MAX_NUM_PROCESSORS; cpu++) {
  134.         highTicks = endSchedPtr->processor[cpu].idleTicksOverflow -
  135.         startSchedPtr->processor[cpu].idleTicksOverflow;
  136.         lowTicks = endSchedPtr->processor[cpu].idleTicksLow 
  137.         - startSchedPtr->processor[cpu].idleTicksLow;
  138.  
  139.         if (highTicks != 0) {
  140.         fprintf(stream, "(High ticks = %d)", highTicks);
  141.         }
  142.         if (timePtr->seconds == 0 && timePtr->microseconds == 0) {
  143.         fprintf(stream, "Idle ticks --/-- = 100%% Idle, Elapsed time ");
  144.         } else {
  145.         lowTicks /= 
  146.           (double)timePtr->seconds 
  147.             + (double) (timePtr->microseconds)/1000000.;
  148.         fprintf(stream, "Idle ticks %0.0f/%d = %6.2f%% Idle, Context Sw. %d inv %d full %d, Elapsed time ",
  149.                    lowTicks,
  150.             endSchedPtr->processor[cpu].idleTicksPerSecond,
  151.             (double)lowTicks/(double)endSchedPtr->processor[cpu].idleTicksPerSecond * 100.,
  152.             endSchedPtr->processor[cpu].numContextSwitches 
  153.                 - startSchedPtr->processor[cpu].numContextSwitches,
  154.                    endSchedPtr->processor[cpu].numInvoluntarySwitches 
  155.                 - startSchedPtr->processor[cpu].numInvoluntarySwitches,
  156.                    endSchedPtr->processor[cpu].numFullCS 
  157.                 - startSchedPtr->processor[cpu].numFullCS);
  158.         }
  159.         PrintTimes(stream, (Proc_ResUsage *)0, timePtr);
  160.     }
  161. }
  162.  
  163.  
  164. /*
  165.  *----------------------------------------------------------------------
  166.  *
  167.  * PrintFsStats --
  168.  *
  169.  *    Print out the filesystem statistics.  If both a start and end
  170.  *    sample of the statistics are given then the differences between
  171.  *    the two are printed.  To just print the total cumulative statistics
  172.  *    from one sample, specify a single Fs_Stats buffer with the 'end'
  173.  *    parameter.
  174.  *
  175.  * Results:
  176.  *    None.
  177.  *
  178.  * Side effects:
  179.  *    Prints to the specified stream
  180.  *
  181.  *----------------------------------------------------------------------
  182.  */
  183. void
  184. PrintFsStats(stream, start, end, verbose)
  185.     FILE *stream;    /* Output stream */
  186.     Fs_Stats *start;    /* 0, or address of "before run" statistics */
  187.     Fs_Stats *end;    /* End of run statistics */
  188.     int verbose;    /* If true, everything is dumped */
  189. {
  190.     register int t1, t2, t3, t4, t5;
  191.     Fs_Stats zeroStats;
  192.  
  193.     if (start == (Fs_Stats *)0) {
  194.     bzero(&zeroStats, sizeof(Fs_Stats));
  195.     start = &zeroStats;
  196.     }
  197.     /*
  198.      * Print cache size
  199.      */
  200.     fprintf(stream, "Cache blocks max %d min %d number %d/%d free %d/%d limit %d\n",
  201.                end->blockCache.maxCacheBlocks,
  202.                end->blockCache.minCacheBlocks,
  203.                start->blockCache.numCacheBlocks,
  204.                end->blockCache.numCacheBlocks,
  205.                start->blockCache.numFreeBlocks,
  206.                end->blockCache.numFreeBlocks,
  207.                end->blockCache.maxNumBlocks);
  208.  
  209.     /*
  210.      * Print bytes read traffic ratio
  211.      */
  212.     t1 = end->blockCache.bytesRead - start->blockCache.bytesRead;
  213.     t2 = end->blockCache.dirBytesRead - start->blockCache.dirBytesRead;
  214.     t3 = end->gen.remoteBytesRead - start->gen.remoteBytesRead;
  215.     t4 = end->gen.fileBytesRead - start->gen.fileBytesRead;
  216.     t5 = end->gen.physBytesRead - start->gen.physBytesRead;
  217.     fprintf(stream, "Bytes read %d+%d remote %d disk %d+%d",
  218.                t1, t2, t3, t4, t5);
  219.     if (t1 + t2 > 0) {
  220. #ifdef stupid_compiler
  221.     fprintf(stream, "\ttraffic ratio %%%d\n",
  222.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  223. #else
  224.     fprintf(stream, "\n");
  225. #endif
  226.     } else {
  227.     fprintf(stream, "\n");
  228.     }
  229.  
  230.     /*
  231.      * Print bytes written traffic ratio
  232.      */
  233.     t1 = end->blockCache.bytesWritten - start->blockCache.bytesWritten +
  234.     (end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  235.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites) *
  236.     FS_BLOCK_SIZE;
  237.     t2 = end->blockCache.dirBytesWritten - start->blockCache.dirBytesWritten;
  238.     t3 = end->gen.remoteBytesWritten - start->gen.remoteBytesWritten;
  239.     t4 = end->gen.fileBytesWritten - start->gen.fileBytesWritten;
  240.     t5 = end->gen.physBytesWritten - start->gen.physBytesWritten;
  241.     fprintf(stream, "Bytes written %d+%d remote %d disk %d+%d",
  242.                t1, t2, t3, t4, t5);
  243. #ifdef stupid_compiler
  244.     if (t1 + t2 > 0) {
  245.     fprintf(stream, "\ttraffic ratio %%%d",
  246.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  247.     }
  248. #endif
  249.     fprintf(stream, "\n");
  250.  
  251.     if (verbose) {
  252.     /*
  253.      * Print device bytes and zero fills
  254.      */
  255.     t1 = end->gen.deviceBytesWritten - start->gen.deviceBytesWritten;
  256.     t2 = end->gen.deviceBytesRead - start->gen.deviceBytesRead;
  257.     fprintf(stream, "Dev bytes read %d written %d\n", t1, t2);
  258.     t1 = end->blockCache.readZeroFills - start->blockCache.readZeroFills;
  259.     t2 = end->blockCache.writeZeroFills1 -
  260.         start->blockCache.writeZeroFills1;
  261.     t3 = end->blockCache.writeZeroFills2 -
  262.         start->blockCache.writeZeroFills2;
  263.     t4 = end->blockCache.fragZeroFills - start->blockCache.fragZeroFills;
  264.     fprintf(stream, "Zero Fills read %d write1 %d write2 %d frag %d\n",
  265.                    t1, t2, t3, t4);
  266.     t1 = end->blockCache.appendWrites - start->blockCache.appendWrites;
  267.     t2 = end->blockCache.overWrites - start->blockCache.overWrites;
  268.     t3 = end->blockCache.domainReadFails -
  269.         start->blockCache.domainReadFails;
  270.     fprintf(stream, "Appends %d Overwrites %d Failed Reads %d\n",
  271.                    t1, t2, t3);
  272.     }
  273.     t1 = end->blockCache.readAccesses - start->blockCache.readAccesses +
  274.      end->blockCache.fragAccesses - start->blockCache.fragAccesses +
  275.      end->blockCache.fileDescReads - start->blockCache.fileDescReads +
  276.      end->blockCache.indBlockAccesses - start->blockCache.indBlockAccesses +
  277.      end->blockCache.dirBlockAccesses - start->blockCache.dirBlockAccesses;
  278.     t2 = end->blockCache.readHitsOnDirtyBlock -
  279.     start->blockCache.readHitsOnDirtyBlock;
  280.     t3 = end->blockCache.readHitsOnCleanBlock -
  281.     start->blockCache.readHitsOnCleanBlock;
  282.     t4 = end->blockCache.fragHits - start->blockCache.fragHits +
  283.      end->blockCache.fileDescReadHits - start->blockCache.fileDescReadHits +
  284.      end->blockCache.indBlockHits - start->blockCache.indBlockHits +
  285.      end->blockCache.dirBlockHits - start->blockCache.dirBlockHits;
  286.     fprintf(stream, "Cache reads %d hits: dirty %d clean %d other %d",
  287.                t1, t2, t3, t4);
  288. #ifdef stupid_compiler
  289.     if (t1 != 0) {
  290.     fprintf(stream, "\thit ratio %%%d",
  291.                (int)((double)(t2+t3+t4)/(double)t1 * 100.));
  292.     }
  293. #endif
  294.     fprintf(stream, "\n");
  295.  
  296.     t1 = end->blockCache.readAheads - start->blockCache.readAheads;
  297.     t2 = end->blockCache.readAheadHits - start->blockCache.readAheadHits;
  298.     t3 = end->blockCache.allInCacheCalls - start->blockCache.allInCacheCalls;
  299.     t4 = end->blockCache.allInCacheTrue - start->blockCache.allInCacheTrue;
  300.     if (t1 > 0) {
  301.     fprintf(stream, "Read Ahead: hits %d/%d all-in-cache %d/%d\n",
  302.             t2, t1, t4, t3);
  303.     }
  304.  
  305.     t1 = end->blockCache.writeAccesses - start->blockCache.writeAccesses +
  306.      end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  307.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites +
  308.      end->blockCache.dirBlockWrites - start->blockCache.dirBlockWrites;
  309.     t2 = end->blockCache.partialWriteHits - start->blockCache.partialWriteHits +
  310.     end->blockCache.fileDescWriteHits - start->blockCache.fileDescWriteHits;
  311.     t3 = end->blockCache.partialWriteMisses -
  312.     start->blockCache.partialWriteMisses;
  313.     t4 = end->blockCache.blocksWrittenThru -
  314.     start->blockCache.blocksWrittenThru;
  315.     fprintf(stream, "Cache writes %d hits %d misses %d thru %d",
  316.                t1, t2, t3, t4);
  317. #ifdef stupid_compiler
  318.     if (t1 != 0) {
  319.     fprintf(stream, "\ttraffic ratio %%%d",
  320.                (int)((double)(t3+t4)/(double)t1 * 100.));
  321.     }
  322. #endif
  323.     fprintf(stream, "\n");
  324.     
  325.     fprintf(stream, "Write thru %d data %d indirect %d desc %d dir %d\n",
  326.                t4,
  327.                end->blockCache.dataBlocksWrittenThru -
  328.                start->blockCache.dataBlocksWrittenThru,
  329.                end->blockCache.indBlocksWrittenThru -
  330.                start->blockCache.indBlocksWrittenThru,
  331.                end->blockCache.descBlocksWrittenThru -
  332.                start->blockCache.descBlocksWrittenThru,
  333.                end->blockCache.dirBlocksWrittenThru -
  334.                start->blockCache.dirBlocksWrittenThru);
  335.     if (end->blockCache.fileDescReads > 0) {
  336.     fprintf(stream, "File descriptor reads %d hits %d writes %d hits %d\n",
  337.                    end->blockCache.fileDescReads -
  338.                    start->blockCache.fileDescReads,
  339.                    end->blockCache.fileDescReadHits -
  340.                    start->blockCache.fileDescReadHits,
  341.                    end->blockCache.fileDescWrites -
  342.                    start->blockCache.fileDescWrites,
  343.                    end->blockCache.fileDescWriteHits -
  344.                    start->blockCache.fileDescWriteHits);
  345.     }
  346.     if (end->blockCache.indBlockAccesses > 0) {
  347.     fprintf(stream, "Indirect block reads %d hits %d writes %d\n",
  348.                end->blockCache.indBlockAccesses -
  349.                start->blockCache.indBlockAccesses,
  350.                end->blockCache.indBlockHits -
  351.                start->blockCache.indBlockHits,
  352.                end->blockCache.indBlockWrites -
  353.                start->blockCache.indBlockWrites);
  354.     }
  355.     if (end->blockCache.dirBlockAccesses > 0) {
  356.     fprintf(stream, "Directory block reads %d hits %d writes %d\n",
  357.                    end->blockCache.dirBlockAccesses -
  358.                    start->blockCache.dirBlockAccesses,
  359.                    end->blockCache.dirBlockHits -
  360.                    start->blockCache.dirBlockHits,
  361.                    end->blockCache.dirBlockWrites -
  362.                    start->blockCache.dirBlockWrites);
  363.     }
  364.     if (end->blockCache.vmRequests > 0) {
  365.     fprintf(stream, "VM requests %d tried %d gave %d\n",
  366.                    end->blockCache.vmRequests -
  367.                    start->blockCache.vmRequests,
  368.                    end->blockCache.triedToGiveToVM -
  369.                    start->blockCache.triedToGiveToVM,
  370.                    end->blockCache.vmGotPage -
  371.                    start->blockCache.vmGotPage);
  372.     }
  373.     fprintf(stream, "Cache blocks created %d, alloc from free %d part %d lru %d\n",
  374.                    end->blockCache.unmapped -
  375.                    start->blockCache.unmapped,
  376.                    end->blockCache.totFree -
  377.                    start->blockCache.totFree,
  378.                    end->blockCache.partFree -
  379.                    start->blockCache.partFree,
  380.                    end->blockCache.lru -
  381.                    start->blockCache.lru);
  382.     if (end->alloc.blocksAllocated > 0) {
  383.     fprintf(stream, "Disk blocks alloc %d free %d search %d/%d hash %d\n",
  384.                    end->alloc.blocksAllocated -
  385.                    start->alloc.blocksAllocated,
  386.                    end->alloc.blocksFreed -
  387.                    start->alloc.blocksFreed,
  388.                    end->alloc.cylsSearched -
  389.                    start->alloc.cylsSearched,
  390.                    end->alloc.cylBitmapSearches -
  391.                    start->alloc.cylBitmapSearches,
  392.                    end->alloc.cylHashes -
  393.                    start->alloc.cylHashes);
  394.     fprintf(stream, "Fragments alloc %d free %d upgrade %d blocks made %d used %d, bad hints %d\n",
  395.                    end->alloc.fragsAllocated -
  396.                    start->alloc.fragsAllocated,
  397.                    end->alloc.fragsFreed -
  398.                    start->alloc.fragsFreed,
  399.                    end->alloc.fragUpgrades -
  400.                    start->alloc.fragUpgrades,
  401.                    end->alloc.fragToBlock -
  402.                    start->alloc.fragToBlock,
  403.                    end->alloc.fullBlockFrags -
  404.                    start->alloc.fullBlockFrags,
  405.                    end->alloc.badFragList -
  406.                    start->alloc.badFragList);
  407.     }
  408.     if (end->nameCache.accesses > 0) {
  409.     fprintf(stream, "Name cache entries %d accesses %d hits %d replaced %d\n",
  410.                end->nameCache.size,
  411.                end->nameCache.accesses -
  412.                start->nameCache.accesses,
  413.                end->nameCache.hits -
  414.                start->nameCache.hits,
  415.                end->nameCache.replacements -
  416.                start->nameCache.replacements);
  417.     }
  418.     fprintf(stream, "Handles %d created %d installed %d hits %d old %d version %d flush %d\n",
  419.                end->handle.exists,
  420.                end->handle.created -
  421.                start->handle.created,
  422.                end->handle.installCalls -
  423.                start->handle.installCalls,
  424.                end->handle.installHits -
  425.                start->handle.installHits,
  426.                0,
  427.                end->handle.versionMismatch -
  428.                start->handle.versionMismatch,
  429.                end->handle.cacheFlushes -
  430.                start->handle.cacheFlushes);
  431.     fprintf(stream, "\tfetched %d hits %d released %d locks %d/%d wait %d\n",
  432.                end->handle.fetchCalls -
  433.                start->handle.fetchCalls,
  434.                end->handle.fetchHits -
  435.                start->handle.fetchHits,
  436.                end->handle.release -
  437.                start->handle.release,
  438.                end->handle.locks -
  439.                start->handle.locks,
  440.                end->handle.locks -
  441.                start->handle.locks,
  442.                end->handle.lockWaits -
  443.                start->handle.lockWaits);
  444.     fprintf(stream, "Segments fetched %d hits %d\n",
  445.                end->handle.segmentFetches -
  446.                start->handle.segmentFetches,
  447.                end->handle.segmentHits -
  448.                start->handle.segmentHits);
  449.     fprintf(stream, "Lookup relative %d absolute %d redirect %d found %d loops %d timeouts %d stale %d\n",
  450.                end->prefix.relative -
  451.                start->prefix.relative,
  452.                end->prefix.absolute -
  453.                start->prefix.absolute,
  454.                end->prefix.redirects -
  455.                start->prefix.redirects,
  456.                end->prefix.found -
  457.                start->prefix.found,
  458.                end->prefix.loops -
  459.                start->prefix.loops,
  460.                end->prefix.timeouts -
  461.                start->prefix.timeouts,
  462.                end->prefix.stale -
  463.                start->prefix.stale);
  464. }
  465.  
  466.  
  467. /*
  468.  *----------------------------------------------------------------------
  469.  *
  470.  * PrintDiskStats --
  471.  *
  472.  *    Print out statistics for the disks.  If both a start and end
  473.  *    sample of the statistics are given then the differences between
  474.  *    the two are printed.  To just print the total cumulative statistics
  475.  *    from one sample, specify a single VmStats buffer with the 'end'
  476.  *    parameter.
  477.  *
  478.  * Results:
  479.  *    None.
  480.  *
  481.  * Side effects:
  482.  *    Prints to the specified stream
  483.  *
  484.  *----------------------------------------------------------------------
  485.  */
  486. void
  487. PrintDiskStats(stream, start, end)
  488.     FILE        *stream;    /* Output stream */
  489.     Sys_DiskStats    *start;    /* 0, or address of "before run" statistics */
  490.     Sys_DiskStats    *end;    /* End of run statistics */
  491. {
  492.     int    i = 0;
  493.     while (1) {
  494.     if (end[i].name[0] == 0) {
  495.         return;
  496.     }
  497.     if (start == 0) {
  498.         fprintf(stream, "Disk (%s, %d): %0.2f%% Idle Reads %d Writes %d\n",
  499.             end[i].name, end[i].controllerID,
  500.             100 * ((float)end[i].idleCount / (float)end[i].numSamples),
  501.             end[i].diskReads, end[i].diskWrites);
  502.     } else {
  503.         fprintf(stream, "Disk (%s, %d) %0.0f%% Idle Reads %d Writes %d\n",
  504.             end[i].name, end[i].controllerID,
  505.             100 * ((float)(end[i].idleCount - start[i].idleCount) /
  506.                    (float)(end[i].numSamples - start[i].numSamples)),
  507.             end[i].diskReads - start[i].diskReads,
  508.             end[i].diskWrites - start[i].diskWrites);
  509.     }
  510.     i++;
  511.     }
  512. }
  513.  
  514.  
  515. /*
  516.  *----------------------------------------------------------------------
  517.  *
  518.  * PrintVmStats --
  519.  *
  520.  *    Print out VM statistics.  If both a start and end
  521.  *    sample of the statistics are given then the differences between
  522.  *    the two are printed.  To just print the total cumulative statistics
  523.  *    from one sample, specify a single VmStats buffer with the 'end'
  524.  *    parameter.
  525.  *
  526.  * Results:
  527.  *    None.
  528.  *
  529.  * Side effects:
  530.  *    Prints to the specified stream
  531.  *
  532.  *----------------------------------------------------------------------
  533.  */
  534. void
  535. PrintVmStats(stream, start, end)
  536.     FILE *stream;    /* Output stream */
  537.     Vm_Stat *start;    /* 0, or address of "before run" statistics */
  538.     Vm_Stat *end;    /* End of run statistics */
  539. {
  540.     register    int    *diffPtr;
  541.     register    int    *startPtr;
  542.     register    int    *endPtr;
  543.     int            i;
  544.     int            inusePages;
  545.     int            totPages;
  546.     int            numModifiedPages;
  547.     Vm_Stat        diffStat;
  548.     int            totPercent;
  549.     int            totFaults;
  550.     int            heapPercent;
  551.     int            stkPercent;
  552.     int            quickPercent;    
  553.     int            totHits;
  554.     int            totPrefetches;
  555.     int            hitPct;
  556.  
  557.     startPtr = (int *)start;
  558.     endPtr = (int *)end;
  559.     diffPtr = (int *)&diffStat;
  560.  
  561.     for (i = 0; 
  562.          i < sizeof(Vm_Stat) / sizeof(int); 
  563.      i++, startPtr++, endPtr++, diffPtr++) {
  564.     *diffPtr = *endPtr - *startPtr;
  565.     }
  566.  
  567.     (void)Vm_Cmd(VM_COUNT_DIRTY_PAGES, &numModifiedPages);
  568.     fprintf(stream, "Kernel VM Pages: %d (Code+Data=%d Stacks=%d)\n",
  569.          end->kernMemPages + end->kernStackPages,
  570.          end->kernMemPages, end->kernStackPages);
  571.     inusePages = end->numDirtyPages + end->numUserPages;
  572.     totPages = end->numFreePages + inusePages;
  573.     fprintf(stream, "User VM Pages:   %d (Free=%d Dirty=%d Res=%d Alloc-list=%d)\n",
  574.         end->numFreePages + end->numDirtyPages + 
  575.         end->numReservePages + end->numUserPages, 
  576.         end->numFreePages, end->numDirtyPages,
  577.         end->numReservePages,
  578.         end->numUserPages);
  579.     fprintf(stream, "Modified pages: Total=%d %%Tot-dirty=%0.2f %%Inuse-dirty=%0.2f\n",
  580.         numModifiedPages,
  581.         (float) (numModifiedPages) / (float)totPages * 100.0,
  582.         (float) (numModifiedPages) / (float)inusePages * 100.0);
  583.     fprintf(stream, "FS Pages: Current=%d Max=%d Min=%d\n", 
  584.         end->fsMap - end->fsUnmap, end->maxFSPages, end->minFSPages);
  585.     fprintf(stream,
  586.          "Faults: %8d (Zero=%d FS=%d Swap=%d Quick=%d Coll=%d)\n", 
  587.          diffStat.totalFaults, diffStat.zeroFilled, diffStat.fsFilled,
  588.          diffStat.psFilled,diffStat.quickFaults, diffStat.collFaults);
  589.     fprintf(stream, "        %8d (Code=%d Heap=%d Stack=%d)\n", 
  590.          diffStat.totalFaults, diffStat.codeFaults, diffStat.heapFaults,
  591.          diffStat.stackFaults);
  592.     fprintf(stream, 
  593.         "Mod page stats:  Pot-mod=%d Not-mod=%d Not-hard-mod=%d\n",
  594.         diffStat.potModPages, diffStat.notModPages, 
  595.         diffStat.notHardModPages);
  596.  
  597.     /*
  598.      * Copy on write. 
  599.      */
  600.     totPages = diffStat.numCOWStkPages + diffStat.numCOWHeapPages;
  601.     totFaults = diffStat.numCOWStkFaults + diffStat.numCOWHeapFaults;
  602.     if (diffStat.numCOWHeapPages > 0) {
  603.     heapPercent = 100.0 * ((float)diffStat.numCOWHeapFaults / 
  604.                       diffStat.numCOWHeapPages);
  605.     } else {
  606.     heapPercent = 0;
  607.     }
  608.     if (diffStat.numCOWStkPages > 0) {
  609.     stkPercent = 100.0 * ((float)diffStat.numCOWStkFaults / 
  610.                       diffStat.numCOWStkPages);
  611.     } else {
  612.     stkPercent = 0;
  613.     }
  614.     if (totPages > 0) {
  615.     totPercent = 100.0 * ((float)totFaults / totPages);
  616.     } else {
  617.     totPercent = 0;
  618.     }
  619.     if (totFaults > 0) {
  620.     quickPercent = 100.0 * ((float)diffStat.quickCOWFaults / totFaults);
  621.     } else {
  622.     quickPercent = 0;
  623.     }
  624.     fprintf(stream, 
  625.         "COW: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  626.         diffStat.numCOWHeapFaults, diffStat.numCOWHeapPages, heapPercent,
  627.         diffStat.numCOWStkFaults, diffStat.numCOWStkPages, stkPercent,
  628.         totFaults, totPages, totPercent);
  629.     fprintf(stream, "     Quick (%d/%d)=%d%%\n",
  630.         diffStat.quickCOWFaults, totFaults, quickPercent);
  631.     /*
  632.      * Copy on reference.
  633.      */
  634.     totPages = diffStat.numCORStkPages + diffStat.numCORHeapPages;
  635.     totFaults = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  636.     if (diffStat.numCORHeapPages > 0) {
  637.     heapPercent = 100.0 * ((float)diffStat.numCORHeapFaults / 
  638.                       diffStat.numCORHeapPages);
  639.     } else {
  640.     heapPercent = 0;
  641.     }
  642.     if (diffStat.numCORStkPages > 0) {
  643.     stkPercent = 100.0 * ((float)diffStat.numCORStkFaults / 
  644.                       diffStat.numCORStkPages);
  645.     } else {
  646.     stkPercent = 0;
  647.     }
  648.     if (totPages > 0) {
  649.     totPercent = 100.0 * ((float)totFaults / totPages);
  650.     } else {
  651.     totPercent = 0;
  652.     }
  653.     fprintf(stream,
  654.             "COR: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  655.         diffStat.numCORHeapFaults, diffStat.numCORHeapPages, heapPercent,
  656.         diffStat.numCORStkFaults, diffStat.numCORStkPages, stkPercent,
  657.         totFaults, totPages, totPercent);
  658.     totPages = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  659.     totFaults = diffStat.numCORCOWStkFaults + diffStat.numCORCOWHeapFaults;
  660.     if (diffStat.numCORCOWHeapFaults > 0) {
  661.     heapPercent = 100.0 * ((float)diffStat.numCORCOWHeapFaults / 
  662.                       diffStat.numCORHeapFaults);
  663.     } else {
  664.     heapPercent = 0;
  665.     }
  666.     if (diffStat.numCORCOWStkFaults > 0) {
  667.     stkPercent = 100.0 * ((float)diffStat.numCORCOWStkFaults / 
  668.                       diffStat.numCORStkFaults);
  669.     } else {
  670.     stkPercent = 0;
  671.     }
  672.     if (totPages > 0) {
  673.     totPercent = 100.0 * ((float)totFaults / totPages);
  674.     } else {
  675.     totPercent = 0;
  676.     }
  677.     fprintf(stream,
  678.             "COR-mod: Heap(%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  679.         diffStat.numCORCOWHeapFaults, diffStat.numCORHeapFaults,heapPercent,
  680.         diffStat.numCORCOWStkFaults, diffStat.numCORStkFaults, stkPercent,
  681.         diffStat.numCORCOWHeapFaults + diffStat.numCORCOWStkFaults,
  682.         diffStat.numCORHeapFaults + diffStat.numCORStkFaults, totPercent);
  683.  
  684.     fprintf(stream, "Swap pages copied: %d\n", diffStat.swapPagesCopied);
  685.     fprintf(stream,
  686.              "Vm allocs: %d (Free=%d From-FS=%d From-alloc-list=%d)\n",
  687.          diffStat.numAllocs, diffStat.gotFreePage, diffStat.gotPageFromFS, 
  688.          diffStat.pageAllocs);
  689.     fprintf(stream, 
  690.          "VM-FS stats: Asked=%d Free-pages=%d Allocs=%d Frees=%d\n",
  691.          diffStat.fsAsked, diffStat.haveFreePage, diffStat.fsMap, 
  692.          diffStat.fsUnmap);
  693.     fprintf(stream, "Alloc-list searches: %d (Free=%d In-use=%d)\n",
  694.          diffStat.numListSearches, diffStat.usedFreePage, 
  695.          diffStat.numListSearches - diffStat.usedFreePage);
  696.     fprintf(stream, "Extra-searches: %d (Lock=%d Ref=%d Dirty=%d)\n",
  697.          diffStat.lockSearched + diffStat.refSearched + 
  698.          diffStat.dirtySearched,
  699.          diffStat.lockSearched, diffStat.refSearched, 
  700.          diffStat.dirtySearched);
  701.     fprintf(stream, "Pages written %d\n", diffStat.pagesWritten);
  702.  
  703.     totPrefetches = diffStat.codePrefetches + diffStat.heapFSPrefetches +
  704.             diffStat.heapSwapPrefetches + diffStat.stackPrefetches;
  705.     if (totPrefetches > 0) {
  706.     totHits = diffStat.codePrefetchHits + diffStat.heapFSPrefetchHits +
  707.           diffStat.heapSwapPrefetchHits + diffStat.stackPrefetchHits;
  708.     fprintf(stream, "Prefetch stats:\n");
  709.     if (diffStat.codePrefetches > 0) {
  710.         hitPct = 100 * ((float)diffStat.codePrefetchHits / 
  711.                 (float)diffStat.codePrefetches);
  712.         fprintf(stream, "    code (%d/%d)=%d%%\n",
  713.             diffStat.codePrefetchHits, diffStat.codePrefetches, hitPct);
  714.     }
  715.     if (diffStat.heapFSPrefetches > 0) {
  716.         hitPct = 100 * ((float)diffStat.heapFSPrefetchHits / 
  717.                 (float)diffStat.heapFSPrefetches);
  718.         fprintf(stream, "    heap-fs (%d/%d)=%d%%\n",
  719.         diffStat.heapFSPrefetchHits, diffStat.heapFSPrefetches, hitPct);
  720.     }
  721.     if (diffStat.heapSwapPrefetches > 0) {
  722.         hitPct = 100 * ((float)diffStat.heapSwapPrefetchHits / 
  723.                 (float)diffStat.heapSwapPrefetches);
  724.         fprintf(stream, "    heap-swp (%d/%d)=%d%%\n",
  725.         diffStat.heapSwapPrefetchHits, diffStat.heapSwapPrefetches, 
  726.         hitPct);
  727.     }
  728.     if (diffStat.stackPrefetches > 0) {
  729.         hitPct = 100 * ((float)diffStat.stackPrefetchHits / 
  730.                 (float)diffStat.stackPrefetches);
  731.         fprintf(stream, "    stack (%d/%d)=%d%%\n",
  732.         diffStat.stackPrefetchHits, diffStat.stackPrefetches, hitPct);
  733.     }
  734.     hitPct = 100 * ((float)totHits / (float)totPrefetches);
  735.     fprintf(stream, "    total (%d/%d)=%d%%\n",
  736.         totHits, totPrefetches, hitPct);
  737.     fprintf(stream, "    aborts=   %d\n", diffStat.prefetchAborts);
  738.     }
  739.  
  740.  
  741.     fprintf(stream, "Contexts stolen %d pmegs stolen %d\n",
  742.          diffStat.machDepStat.stealContext, diffStat.machDepStat.stealPmeg);
  743. }
  744.  
  745.  
  746.  
  747. /*
  748.  *----------------------------------------------------------------------
  749.  *
  750.  * PrintIntervalStats --
  751.  *
  752.  *    Print out values over intervals.  For now, only idle time
  753.  *    is printed, plus a smattering of other things.
  754.  *
  755.  * Results:
  756.  *    None.
  757.  *
  758.  * Side effects:
  759.  *    Prints to the s
  760.  *
  761.  *----------------------------------------------------------------------
  762.  */
  763. void
  764. PrintIntervalStats(stream, intervals, fsArray,
  765.            vmArray, diskArray, schedArray, netArray)
  766.     FILE *stream;
  767.     int intervals;
  768.     Fs_Stats *fsArray;
  769.     Vm_Stat *vmArray;
  770.     Sys_DiskStats *diskArray;
  771.     Sched_Instrument *schedArray;
  772.     Net_EtherStats *netArray;
  773. {
  774.     int i;
  775.     Sched_Instrument *startSchedPtr, *endSchedPtr;
  776.     Net_EtherStats *startNetPtr, *endNetPtr;
  777.     double     lowTicks;
  778.     extern int repeatInterval;
  779.  
  780.     fprintf(stream, "Interval measurements of idle ticks:\n");
  781.     startSchedPtr = &schedArray[0];
  782.     endSchedPtr = &schedArray[0];
  783.     for (i = 0; i < intervals; i++) {
  784.     endSchedPtr++;
  785.         lowTicks = endSchedPtr->processor[0].idleTicksLow 
  786.         - startSchedPtr->processor[0].idleTicksLow;
  787.     lowTicks /= repeatInterval;
  788.     fprintf(stream, "%d %0.0f\n", i, lowTicks);
  789.     startSchedPtr++;
  790.     }
  791.  
  792.  
  793.     fprintf(stream, "Interval measurements of network traffic (in, out):\n");
  794.     startNetPtr = &netArray[0];
  795.     endNetPtr = &netArray[0];
  796.     for (i = 0; i < intervals; i++) {
  797.     endNetPtr++;
  798.     fprintf(stream, "%d %u %u\n", i, 
  799.         endNetPtr->bytesReceived - startNetPtr->bytesReceived,
  800.             endNetPtr->bytesSent - startNetPtr->bytesSent);
  801.     startNetPtr++;
  802.     }
  803. }
  804.  
  805. @
  806.  
  807.  
  808. 1.1
  809. log
  810. @Initial revision
  811. @
  812. text
  813. @d18 1
  814. d715 61
  815. @
  816.